import Vue from 'vue';
// 导出Vue对象
let idCounter = 5;
export default new Vue({
    data() {
        return {
            list: [
                {
                    id: 1,
                    value: "插花",
                    isDone: false,
                },
                {
                    id: 2,
                    value: "绘画",
                    isDone: false,
                },
                {
                    id: 3,
                    value: "运动",
                    isDone: false,
                },
                {
                    id: 4,
                    value: "看书",
                    isDone: false,
                },
            ],
            showingList: [
                {
                    id: 1,
                    value: "插花",
                    isDone: false,
                },
                {
                    id: 2,
                    value: "绘画",
                    isDone: false,
                },
                {
                    id: 3,
                    value: "运动",
                    isDone: false,
                },
                {
                    id: 4,
                    value: "看书",
                    isDone: false,
                },
            ],

        };
    },
    created() {
        this.$on('onAdd', (inputValue) => {
            this.list.push({
                id: idCounter++,
				value: inputValue,
                isDone: false,
			});
			this.showingList = this.list.concat();
			this.inputValue = "";
        });
        this.$on('getAllTasks', () => {
            this.showingList = this.list.concat();
        });
        this.$on('getIncomplete', () => {
            this.showingList = this.list.filter(item => !item.isDone);
        });
        this.$on('getComplete', () => {
            this.showingList = this.list.filter(item => item.isDone);
        });
        this.$on('onDelete', () => {
            this.list = this.list.filter(item => !item.isDone);
            this.showingList = this.list.concat();
        });
    }
})